﻿using System;
using System.Windows.Forms;
using csvmb.app.boards;
using csvmb.contracts.infrastructure;
using csvmb.csvadapter;
using csvmb.csvadapter.contracts;
using csvmb.csvwerk;
using csvmb.gui;
using csvmb.index;
using csvmb.index.contracts;

namespace csvmb.app
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var gui = new Gui();

            IIndex idx = new Index();
            IDateiadapter adap = new Dateiadapter();

            new Mainboard(
                gui, 
                new Datei_öffnen(
                    Inject(new Datenzeilen_Positionen_lesen(), adap),
                    Inject(new Zeilen_indizieren(), idx),
                    new Blaetteranfrage_konstruieren()), 
                new Blättern(
                    new Header_bestimmen(
                        Inject(new Erste_Zeile_lesen(), adap),
                        new Spaltennamen_bestimmen()),
                    new Datensätze_zu_Ausschnitt_laden(
                        Inject(new Byte_Position_des_Ausschnitts_bestimmen(), idx),
                        Inject(new Datenzeilen_ab_Position_lesen(), adap),
                        new Datensaetze_erstellen()),
                    Inject(new Navigieren(), idx),
                    new ViewModel_bauen()));

            ((IEntryPoint)gui).Run(args);
        }


        private static TPart Inject<TPart, TDependency>(TPart part, TDependency dependency) where TPart : IDependsOn<TDependency>
        {
            (part as IDependsOn<TDependency>).Inject(dependency);
            return part;
        }
    }
}
